$('document').ready(function() {
	$('#chat_field').val("Say something");
	$('#chat_field').click(function() {if ($(this).val() == "Say something") $(this).val('');});
	$('#chat_field').blur(function() {if ($(this).val() == '') $(this).val("Say something");});
	$('#chat_send').click(function(){updateChat();});
	$('#chat_field').bind('keypress', function(e) {
		var code = (e.keyCode ? e.keyCode : e.which);		
		if(code == 13) updateChat();
	});
	$('#footer_buttons').hide();
	
	newGame();
});

function updateChat() {
	if ($('#chat_field').val() != '') {
		var new_row = $('#chat_field').val();
		$('#chat_field').val('');
		$('#conversation').append(">>"+new_row+"<br />");
	}
	return false;
}

function newGame() {
	$.getJSON('game', {action:"new_game"},function(data) {
		$('td[id^=score_]').each(function() {
			$(this).html(data[$(this).attr('id')]);
		});
		$('div#player_cards').html(data['person_card1']+" / "+data['person_card2']);
		$('div#player_'+data['person_position']).addClass('player_active');
		$('div#footer_buttons').fadeIn('slow');
		$('div#footer_buttons div').addClass('button_active');
	});
}